import { ImageResponse } from 'next/og'; import { getAssetBySlug } from '@/lib/queries/assets'; import { catName } from '@/lib/taxonomy'; import { ogMark } from '@/components/layout/logo'; export const runtime = 'nodejs'; export const alt = 'RareIndex asset card'; export const size = { width: 1200, height: 630 }; export const contentType = 'image/png'; function money(v: number | null): string { if (v === null) return 'Data unavailable'; return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: v >= 1000 ? 0 : 2 }).format(v); } export default async function Image({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; const a = await getAssetBySlug(slug); const title = a?.title ?? 'RareIndex'; const cat = a ? catName(a.categorySlug) : ''; const riv = a ? money(a.rivUsd) : ''; const chg = a?.change30d ?? null; return new ImageResponse( (
{ogMark(44)} Rare Index · {cat}
{title.length > 80 ? `${title.slice(0, 79)}…` : title}
RareIndex Valuation {riv} {chg !== null ? = 0 ? '#34c47c' : '#ef5a5f' }}>{`${chg >= 0 ? '+' : ''}${(chg * 100).toFixed(1)}% 30D`} : null}
{a ? `${a.salesCount.toLocaleString('en-US')} verified sales · ${a.activeListings.toLocaleString('en-US')} active listings · www.rareindex.io` : 'www.rareindex.io'}
), { ...size }, ); }